﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace HY.BLL.oa
{
 public    class task
    {

     public static DataTable get_list(string us)
     {
         string sqltxt = "select * from task where  [user]='" + us + "'  ";

         sqltxt = sqltxt + " order by sid desc ";
         DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
         return dt;
     }

     /// <summary>
     /// 当前
     /// </summary>
     /// <param name="dts"></param>
     /// <returns></returns>
     public static DataTable get_list_c(string us,string whe)
     {
         string sqltxt = "select * from task where   [user]='" + us + "'  and  status=0 and dt<=getdate()  ";
         if (whe != "") sqltxt =sqltxt+ " and " + whe;
         sqltxt = sqltxt + " order by sid desc ";
         DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
         return dt;
     }

     /// <summary>
     /// 未来
     /// </summary>
     /// <param name="dts"></param>
     /// <returns></returns>
     public static DataTable get_list_y(string us, string whe)
     {
         string sqltxt = "select * from task where   [user]='" + us + "' and status=0   ";
         if (whe != "") sqltxt = sqltxt + " and " + whe;
         sqltxt = sqltxt + " order by sid desc ";
         DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
         return dt;
     }

     public static DataTable get_list_y_top(string us, string whe)
     {
         string sqltxt = "select top 20 * from task where   [user]='" + us + "' and status=0   ";
         if (whe != "") sqltxt = sqltxt + " and " + whe;
         sqltxt = sqltxt + " order by sid desc ";
         DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
         return dt;
     }

     /// <summary>
     /// 已过期 
     /// </summary>
     /// <param name="dts"></param>
     /// <returns></returns>
     public static DataTable get_list_n(string us, string whe)
     {
         string sqltxt = "select * from task where   [user]='" + us + "' and status=1  ";
         if (whe != "") sqltxt = sqltxt + " and " + whe;
         sqltxt = sqltxt + " order by sid desc ";
         DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
         return dt;
     }

     public static DataTable get_list(string us, string whe)
     {
         string sqltxt = "select * from task where   [user]='" + us + "'    ";
         if (whe != "") sqltxt =sqltxt+ " and " + whe;

                sqltxt = sqltxt + " order by sid desc ";
         DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
         return dt;
     }


     public static int ins_task(string user,string dt,string memo )
     {
         string sqltxt = "insert into task values(N'"+user+"',N'"+memo+"',N'"+dt+"',N'',0)  ";

         return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
      
     }

     public static int ups_task(string sid,string user, string dt, string memo)
     {
         string sqltxt = "update task set [user]=N'" + user + "',tmemo=N'" + memo + "',dt='" + dt + "' where sid="+sid+"  ";

         return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);

     }

     /// <summary>
     /// 删除一条数据
     /// </summary>
     public static int DeleteList(string sidlist)
     {
         string sqltxt = "delete task where sid in(" + sidlist + ") ";
         return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
     }

    }
}
